-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-1406] [BUG] Fix DLManagedTensor deleter #15016
Conversation
Waiting for #15015 |
@@ -818,10 +818,12 @@ MXNET_DLL int MXNDArrayToDLPack(NDArrayHandle handle, | |||
* The memory is retained until the NDArray went out of scope. | |||
* | |||
* \param dlpack the pointer of the input DLManagedTensor | |||
* \param transient_handle whether the handle will be destructed before calling the deleter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before calling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is false, the DLManagedTensor handle won't be freed after the call, and deleter will free it.
If it is true, the DLManagedTensor handle will be freed by the caller.
@@ -4156,7 +4156,7 @@ def from_dlpack(dlpack): | |||
assert ctypes.pythonapi.PyCapsule_IsValid(dlpack, _c_str_dltensor), ValueError( | |||
'Invalid DLPack Tensor. DLTensor capsules can be consumed only once.') | |||
dlpack_handle = ctypes.c_void_p(ctypes.pythonapi.PyCapsule_GetPointer(dlpack, _c_str_dltensor)) | |||
check_call(_LIB.MXNDArrayFromDLPack(dlpack_handle, ctypes.byref(handle))) | |||
check_call(_LIB.MXNDArrayFromDLPack(dlpack_handle, False, ctypes.byref(handle))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if transient_handle
is false, it means the dlpack_handle won't be free'd any time soon? However, how do we control when the dlpack_handle will be free'd?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It means deleter will free it
handle = NDArrayHandle() | ||
check_call(_LIB.MXNDArrayFromDLPack(address, ctypes.byref(handle))) | ||
check_call(_LIB.MXNDArrayFromDLPack(ctypes.byref(c_obj), True, ctypes.byref(handle))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the handle here is transient handle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bc the DLManagedTensor here is freed immediately after this call
The implication here:
|
@mxnet-label-bot add [C API, NDArray] |
In the old implementation, the deleter will release the object NDArrayDLManager NDArrayDLManager consists of DLManagerTensor It is not necessary to release DLManagerTensor again. Edit: |
Thanks @wkcn for the in-depth discussion! |
* Fix * Fix * Retrigger
* Fix * Fix * Retrigger
Description
This PR fixes a bug that causes recent crash in DGL. Please refer to dmlc/dlpack#39 for details.
CC: @zheng-da
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
MXNDArrayFromDLPack
to accept an additional flag indicating whether the handle will be freed before calling deleter.Comments
None